import speech_recognition as sr

def speech_to_text():
    recognizer = sr.Recognizer()
    with sr.Microphone() as source:
        print("🎤 请开始说话...")
        audio = recognizer.listen(source)
        try:
            text = recognizer.recognize_google(audio, language="zh-CN")
            print("🔊 识别结果:", text)
            return text
        except sr.UnknownValueError:
            print("⚠️ 无法识别语音")
        except sr.RequestError as e:
            print(f"⚠️ 请求出错: {e}")
    return None